package day_2022_7_to_8.day48;

import java.util.LinkedList;
import java.util.List;

/**
 * 组合
 * @author haomin
 * @date 2022/07/15 11:12
 **/
public class Day1_1_Num77_combine {
    public List<List<Integer>> result = new LinkedList<>();
    public List<Integer> ret = new LinkedList<>();

    public List<List<Integer>> combine(int n, int k) {
        dfs(1,n,k);
        return result;
    }

    private void dfs(int left, int right, int k) {
        if(ret.size() == k){
            result.add(new LinkedList<>(ret));
        }
        for(int i = left;i <= right;i++){
            ret.add(i);
            dfs(i+1,right,k);
            ret.remove(ret.size()-1);
        }
    }
}